<%@ page language="java" import="java.util.*,ct.zxd.db.*" pageEncoding="utf-8"
contentType="text/html"%>

<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<meta name="renderer" content="webkit">
	<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
	<title></title>
	<link rel="stylesheet" href="css/pintuer.css">
	<link rel="stylesheet" href="css/admin.css">
	<script src="js/jquery.js"></script>
	<script src="js/pintuer.js"></script>
 </head>
 <style type="text/css">
 .file {
    position: relative;
    display: inline-block;
    overflow: hidden;
    
     
    /*text-decoration: none;
    text-indent: 0;
    line-height: 20px;
     background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;*/
}
.file input {
    position: absolute;
    /*font-size: 100px;*/
    right: 0;
    top: 0;
    opacity: 0;
}
</style>
<script type="text/javascript">
	function selectImageDone(url, index){
		url=url.substr(url.lastIndexOf("\\")+1);
		var imgInput = document.getElementById("imgUrlDetail");
		if(index == 1){
			imgInput = document.getElementById("imgUrl");
		}
		
		imgInput.value=url;
		imgInput.attributes["data-image"].nodeValue = "";
		dishform.encoding="multipart/form-data";
	}
</script>
  <%
	String shop = request.getParameter("shop");
	//shop = new String(shop.getBytes("iso-8859-1"),"utf-8");
	
	Dao dao = new Dao();
	List<Map<String,Object>>cateList = dao.getTableByid("category", shop, null);
	
	String updateShowID = request.getParameter("show");
	updateShowID = updateShowID==null ? "" : updateShowID;
	//updateShowID = updateShowID==null ? "" : new String(updateShowID.getBytes("iso-8859-1"),"utf-8");
	
	String imageURL="",stockNumber="",price="",category_name="", introduce = "", front="0";

	String updateCateName = request.getParameter("cateName");
	if(updateCateName==null){
		updateCateName = "";
	}else{
		//updateCateName = new String(updateCateName.trim().getBytes("iso-8859-1"),"utf-8");
		updateCateName = updateCateName.trim();
		List<Map<String,Object>>dishList = dao.getTableByid("dish", shop, updateShowID);
		if(dishList.size()>0){
			Map<String,Object> map = dishList.get(0);
	       	imageURL = map.get("imageURL").toString();
	       	price = map.get("price").toString();
	       	stockNumber = map.get("stockNumber").toString(); 
	       	category_name = map.get("category_name").toString();
	       	introduce = map.get("introduce").toString();
	       	front = map.get("front").toString();
       	}else{
       		imageURL = "";
	       	price = "";
	       	stockNumber = ""; 
	       	category_name = "";
	       	introduce = "";
	       	front = "0";
       	}	
	}

	String errName = (String)request.getAttribute("errName");
	if(errName==null){
		errName="";
	}else{
		updateCateName = "";
	}
	
	String errFile = (String)request.getAttribute("errFile");
	if(errFile==null){
		errFile="";
	}
	
	String buttonStyle = "button bg-main icon-check-square-o";
	String buttonText = "提交";
	String buttonAbled = "";
	
	String flag = request.getParameter("flag");
	if(flag==null){
	   buttonAbled = "disabled=true";
	}else if(flag.equals("del")){
			buttonStyle = "button bg-red icon-trash-o";
			buttonText = "删除";
	}
%>
  <body>
		
	<div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 增加内容</strong></div>
  <div class="body-content">
    <form id="dishform" method="post" class="form-x" action="HandleDish?flag=<%=flag%>&shop=<%=shop%>" >   

     <div class="form-group">
        <div class="label">
          <label>编号：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="<%=updateShowID %>" name="showid"  readonly= true/>
          <div class="tips"></div>
        </div>
      </div> 
      
      <div class="form-group">
        <div class="label">
          <label>名称：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" maxlength="100" value="<%=updateCateName %>" name="title" data-validate="required:请输入名称" />
          <div class="tips"></div>
          &nbsp;&nbsp;
          <font color="red"><%=errName %></font>
        </div>
      </div>

      <div class="form-group">
        <div class="label">
          <label>商品图片：</label>
        </div>
        
        <input type="text" id="imgUrl" name="img" class="input tips" style="width:25%; float:left;"  value="<%=imageURL%>" data-toggle="hover" data-place="right" data-image="<%=imageURL%>" data-validate="required:请选择图片"/>
		<a href="javascript:;" class="file button bg-blue margin-left" style="float:left;">选择图片
    		<input type="file" onchange="selectImageDone(this.value, 1);" name="file">
		</a>
        <div class="tipss">图片大小不超过2M</div>
        <font color="red"><%=errFile %></font>
       
      </div>

<div class="form-group">
        <div class="label">
          <label>价格：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="<%=price %>" name="price" data-validate="required:请输入价格" />
          <div class="tips"></div>
          <!-- 请输入整数 -->
        </div>
      </div>
      
      <div class="form-group">
        <div class="label">
          <label>详情图片：</label>
        </div>
        
        <input type="text" id="imgUrlDetail" name="imgDetail" class="input tips" style="width:25%; float:left;"  value="<%=introduce%>" data-toggle="hover" data-place="right" data-image="<%=introduce%>" data-validate="required:请选择图片"/>
		<a href="javascript:;" class="file button bg-blue margin-left" style="float:left;">选择图片
    		<input type="file" onchange="selectImageDone(this.value, 2);" name="fileDetail">
		</a>
        <div class="tipss">图片大小不超过2M</div>
        <font color="red"><%=errFile %></font>
       
      </div>

	<div class="form-group">
        <div class="label">
          <label>库存：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="<%=stockNumber %>" name="stock" data-validate="required:请输入库存数" />
          <div class="tips"></div>
        </div>
      </div>

	<div class="form-group">
        <div class="label">
          <label>首页推荐：</label>
        </div>
        <div class="field">
	        <select class="input w50" name="front" size="1">
				<option value="1" <%=front.equals("1")?"selected":"" %>>是</option>
				<option value="0" <%=front.equals("0")?"selected":"" %>>否</option>
	  		</select>
          <div class="tips"></div>
        </div>
      </div>

	<div class="form-group">
        <div class="label">
          <label>分类：</label>
        </div>
        <div class="field">
          <select class="input w50" name="category" size="1">
          <%
          	if(cateList!=null){
       			for(Map<String,Object> map : cateList){
       				String cateid = map.get("category_id").toString();
       				String name = map.get("name").toString();
           %>
			<option value="<%=name+"-"+cateid%>" <%=name.equals(category_name)?"selected":"" %>><%=name%></option>
		<%}} %>
	  </select>
          <div class="tips"></div>
        </div>
      </div>
    
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <button class="<%=buttonStyle %>" type="submit" <%=buttonAbled %>> <%=buttonText %></button>
        </div>
      </div>
    </form>
  </div>    

  </body>
</html>
